package cn.wsalix.templet.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import cn.anlaser.entity.SimpleEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * @author jskyme 模板实体
 */
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "SITE_PAGE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(callSuper = false)
public class SitePage extends SimpleEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4173272473220310459L;
	private boolean isDefault;
	@Column(name = "MENU_URL", nullable = false, length = 255)
	private String menuUrl;// web访问路径，相对位置，通过outFile生成
	@Column(name = "TEMP_FILE", nullable = false, length = 255)
	private String tempFile;// 模板文件位置相对路径

	@Column(name = "OUT_FILE", nullable = false, length = 255)
	private String outFile;// 输出文件位置
	/*
	 * @JsonIgnore
	 * 
	 * @ManyToOne(cascade=CascadeType.MERGE,optional=false,fetch=FetchType.LAZY)
	 * 
	 * @JoinColumn(name = "SITE_TEMP_ID") private SiteTemplet siteTemplet;
	 * 
	 * @Transient private Long siteTempletId;
	 */
	@JsonIgnore
	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_SP_SITE"), name = "SITE_ID")
	private SiteInfo siteInfo;
	@JsonIgnore
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "sitePage")
	private List<SitePagePlace> sitePagePlaces;

	@JsonIgnore
	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_SP_TP"), name = "TEMPLET_PAGE_ID")
	private TempletPage templetPage;
	@Transient
	private Long templetPageId;

}
